<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 沙箱语法糖 
        // 尽可能简化沙箱模式的语法 
        // 利用getter 和setter 来操作 

        // 因为沙箱模式就是在获取和修改数据 
        function outer(){
            let num1 = 100;
            let num2 = 200;
            const obj = {
                get fn1(){
                    return num1
                },
                get fn2(){
                    return num2
                },
                set fn3(val){
                    num1 = val
                },
                set fn4(val){
                    num2 = val
                }
            
            }

            return obj
        }


        // const o1 = outer();
        // console.log(o1.fn1);
        // o1.fn3 = 666
        // console.log(o1.fn1);

        // const o2 = outer();
        // console.log(o2.fn1);
        // o2.fn3 = 999
        // console.log(o2.fn1);
    </script>
</body>
</html>